﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace SLBehaviourSystem
{
    [ActionComponent]
    public class AnimatorComponent : BehaviourComponent
    {
        Animator animator;
        string Key;
        int State;
        protected override void OnInit()
        {
            base.OnInit();
            animator = GetComponentInChildren<Animator>();
        }
        protected override void OnBindNode()
        {
            base.OnBindNode();
            Key = node.BehaviourData.GetString("Key");
            State = node.BehaviourData.GetInt("State");
        }

        public override BehaviourNodeState Excute()
        {
            animator.SetInteger(Key, State);
            animator.Update(Time.deltaTime);
            return BehaviourNodeState.Success;
        }

        public override void Reset()
        {
            base.Reset();
            animator.Update(Time.deltaTime);
        }
    }
}
